/**
 * 签到记录
 */
$(function () {
    $("#page").load(URI + "/rbac/html/page.html");
});

//查询所有数据
function findAll() {
    //trim()去掉两边的空格
    let data = {
        nickName: $("#nickName").val(),
        signStatus:$("#signStatus").val(),
        userId:sessionStorage.getItem("userId"),
        pageNum: $("#pageNum").val(),
        pageSize: $("#pageSize").val()
    };
    let result = myAjax("/api/stu/student/getSignRecord", data, "post");
    // console.log(resultList);
    // let  result = adminLogin(resultList);
    // 总条数
    if ($.isEmptyObject(result)) {
        alert("您没有权限访问!!!")

    }
    if (result) {
        $("#totalCount").html(result.data.count);
        setData(result.data.pageInfo.list);
    }
}

//遍历查询到的数据
function setData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += " <tr >\n" +
            "            <td>" + data[i].id + "</td>\n" +
            "            <td title='" + data[i].nickName + "'>" + clearNull(data[i].nickName) + "</td>\n" +
            "            <td title='" + data[i].signStatus + "'>" + clearNull(data[i].signStatus) + "</td>\n" +
            "            <td title='" + data[i].lateTime + "'>" + clearNull(data[i].lateTime) + "</td>\n" +
            "            <td title='" + data[i].signTime + "'>" + clearNull(data[i].signTime) + "</td>\n" +
            "            <td title='" + data[i].signUpdateTime + "'>" + clearNull(data[i].signUpdateTime) + "</td>\n" +
            "          </tr>";
    }
    $("#tbody").html(html);
}

/***
 * 清除数据中的undefined和null将其置换为空，不显示
 */

function clearNull(value) {
    return value === null || value === undefined ? "" : value;
}


/***
 * 删除功能
 */
function del(id) {
    let result = myAjax("/api/rb/user/del", {id: id}, "delete");
    if (result.code === 200) {
        //删除成功，就重新查询数据
        alert("删除成功(== ^^ ==)!");
        findAll();
    } else {
        alert("删除失败(╥╯^╰╥)！")
    }
}

/**
 * 签到
 */
// function sign(id) {
//     sessionStorage.setItem("newUserId",id);
//     x_admin_show('编辑', URI + '/rbac/html/student/sign-update.html', 600, 600);
// }



function sign(id) {
    let data={
        userId:id,
        status:$("input:radio[name='status']:checked").val(),
        lateTime:$("#lateTime").val()
    };
    let result = myAjax("/api/stu/student/sign", data, "post");
    if (result.data === 1) {
        //签到成功
        alert(result.message);
        x_admin_father_reload();
    } else {
        alert(result.message);
    }
}

